<?php
require_once '../classes/includeAll.php';
$title="Service Meldung";
$head ='<link rel="stylesheet" type="text/css" href="../design/css/flag.css">'.
        '<script src="../javascript/pagesJavascript/flag.js" type="text/javascript"></script>';
require '../resources/getConnection.php';
$showAll  = false;

$flagClass = new Flags($connection);
$all = $flagClass->GetAllFlags($showAll);
if(isset($_GET["sub"]))
{
  if($_GET["sub"]=="Alle anzeigen")
    $showAll=TRUE;
  else if($_GET["sub"]=="Tabelle leeren")
    $flagClass->RemoveAllFlags();
}

$flagClass = new Flags($connection);
$all = $flagClass->GetAllFlags($showAll);
$connection->disconnectDB();
$search = array ("-", "ae",     "ue",     "oe");
$replace = array(" ", "&auml;", "&uuml;", "&ouml;");

require '../menu/head.php';
echo '<h1>Service Meldungen</h1>';
echo '<table id="flagTable"><thead><tr><th>Datum</th><th>Typ</th><th></th><th>Inhalt</th></tr></thead><tbody>';
foreach ($all as $flag) {
echo'<tr>';
echo "<td>$flag[0]</td>";
echo "<td>$flag[1]</td>";
if($flag[1]=="FullScanProgress")
  $flagMeaning = (new allFlags())->FullscanProgressFlags;
else
  $flagMeaning = (new allFlags())->GlobalFlags;
$outputstr="";
$img="";

if($flag[2]!=0)
{
  foreach ($flagMeaning as $key => $value) {
    if(($flag[2] & $value)>0)
    {
      $str= str_replace($search, $replace, $key);
      $outputstr.=$str.'<br>';
      if(strpos($str, "Fehler")!==false)
      {
        $img.='<img src="../design/pictures/error.png" width="16" alt="X"/>&nbsp;<br>';
      }
      else if(strpos($str, "Warnung")!==false)
      {
        $img.='<img src="../design/pictures/warning.png" width="16" alt="!"/>&nbsp;<br>';
      }
      else
      {
        $img.='<img src="../design/pictures/tick.png" width="16" alt=""/>&nbsp;<br>';
      }
    }
  }
}
else 
{
  $outputstr = "Keine Meldung";
}
echo "<td>$img</td><td>$outputstr</td>";
echo '</tr>';
}
echo '</tbody></table>'; ?>

<form action="flag.php" id="frm" method="GET"></form><p>
  <?php if(!$showAll) {echo '<input type="button" value="Alle anzeigen" name="submit" class="btns"/>&nbsp;&nbsp;&nbsp;&nbsp;';}?><input type="button" value="Tabelle leeren" name="submit" class="btns"/>
</p>

<?php
require '../menu/footer.php';
?>